package cn.iocoder.yudao.module.famous.doctor.controller.app.prescription;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.servlet.http.HttpServletResponse;
import javax.validation.*;
import java.io.IOException;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

import cn.iocoder.yudao.module.famous.doctor.controller.admin.prescription.vo.*;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.prescription.PrescriptionDO;
import cn.iocoder.yudao.module.famous.doctor.convert.prescription.PrescriptionConvert;
import cn.iocoder.yudao.module.famous.doctor.service.prescription.PrescriptionService;

@Tag(name = "用户 APP - 我的处方")
@RestController
@RequestMapping("/famous.doctor/prescription/app")
@Validated
public class AppPrescriptionController {

    @Resource
    private PrescriptionService prescriptionService;

    @PostMapping("/create")
    @Operation(summary = "创建处方")
    public CommonResult<Long> createPrescription(@Valid @RequestBody PrescriptionCreateReqVO createReqVO) {
        return success(prescriptionService.createPrescription(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新处方")
    public CommonResult<Boolean> updatePrescription(@Valid @RequestBody PrescriptionUpdateReqVO updateReqVO) {
        prescriptionService.updatePrescription(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除处方")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deletePrescription(@RequestParam("id") Long id) {
        prescriptionService.deletePrescription(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得处方")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<PrescriptionRespVO> getPrescription(@RequestParam("id") Long id) {
        PrescriptionDO prescription = prescriptionService.getPrescription(id);
        return success(PrescriptionConvert.INSTANCE.convert(prescription));
    }

    @GetMapping("/list")
    @Operation(summary = "获得处方列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<PrescriptionRespVO>> getPrescriptionList(@RequestParam("ids") Collection<Long> ids) {
        List<PrescriptionDO> list = prescriptionService.getPrescriptionList(ids);
        return success(PrescriptionConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得处方分页")
    public CommonResult<PageResult<PrescriptionRespVO>> getPrescriptionPage(@Valid PrescriptionPageReqVO pageVO) {
        PageResult<PrescriptionDO> pageResult = prescriptionService.getPrescriptionPage(pageVO);
        return success(PrescriptionConvert.INSTANCE.convertPage(pageResult));
    }

}
